package com.remotebluetooth;

import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

import javax.bluetooth.RemoteDevice;
import javax.microedition.io.StreamConnection;

public class ProcessConnectionThread extends Thread{

	private StreamConnection mConnection;
	
	public ProcessConnectionThread(StreamConnection connection)
	{
		mConnection = connection;
		start();
	}
	
	@Override
	public void run() {
		try {
			
			// prepare to receive data
			InputStream inputStream = mConnection.openInputStream();
			RemoteDevice dev = RemoteDevice.getRemoteDevice(mConnection);
	        System.out.println("Remote device address: "+dev.getBluetoothAddress());
	        System.out.println("Remote device name: "+dev.getFriendlyName(true));
	        while (true) {
	        	try {
	        		BufferedReader bReader=new BufferedReader(new InputStreamReader(inputStream));
	        		String line=bReader.readLine();
		            System.out.println(line);
				} catch (Exception e) {
					e.printStackTrace();
				}    
        	}
        } catch (Exception e) {
    		e.printStackTrace();
    	}
	}
}
